package com.itheima.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author 王加鑫
 * @Date 2021/5/25 15:52
 * @Version 1.0
 */
public class ClientDemo01 {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        while (true){
            Socket socket = new Socket("192.168.22.81",10001);
            OutputStream os = socket.getOutputStream();
            InputStream is = socket.getInputStream();
            String s = sc.next();
            if(!"886".equals(s)){
                os.write(s.getBytes());
                os.flush();
                //关闭os
                socket.shutdownOutput();
            }else {
                os.close();
                is.close();
                socket.close();
                break;
            }
            byte[] bytes = new byte[1024];
            int i;
            while ((i = is.read(bytes)) != -1){
                System.out.println(new String(bytes,0,i));
            }
        }
    }
}
